import store from '@/store'
import { makeUUID } from '@/utils'

function UpdateSelection(selection) {
  // console.log('更新当前选择集:', selection)
  // 更新选择集
  store.dispatch('editor/diagram/updateSelection', {
    stamp: makeUUID(),
    selection
  })
}

function UpdateSubject(observer, subjects) {
  // console.log(observer, '观察目标有变化:', subjects)
  // 更新被观察图元的时间戳
  store.dispatch('editor/diagram/updateSubjects', {
    stamp: makeUUID(),
    observer,
    subjects
  })
}

// 更新鼠标位置信息
function UpdateScale(scale) {
  store.dispatch('editor/diagram/setScale', scale)
}

// 更新鼠标位置信息
function UpdateMousePosition({ x, y, z }) {
  // console.log('更新鼠标位置信息', { x, y, z })
  // toFixed(2)函数的精度不准确,改用自定义方法保留小数点2位
  const f = x => Math.round(x * 100) / 100
  store.dispatch('editor/diagram/updateMousePosition', {
    x: f(x),
    y: f(y),
    z: f(z)
  })
}

function Print(msg) {
  store.dispatch('editor/diagram/print', msg)
}

function SetMode(mode) {
  store.dispatch('editor/diagram/setMode', mode)
}

export default {
  UpdateSelection,
  UpdateSubject,
  UpdateMousePosition,
  UpdateScale,
  Print,
  SetMode
}
